package com.example.unique

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity


class EditProfileActivity : AppCompatActivity() {

    private lateinit var editUserName: EditText
    private lateinit var editUserAcademy: EditText
    private lateinit var editUserClub: EditText
    private lateinit var editUserPassword:EditText
    private lateinit var saveButton: Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_profile)

        // 获取传递过来的数据
        val userName = intent.getStringExtra("user_name")
        val userAcademy = intent.getStringExtra("user_academy")
        val userClub = intent.getStringExtra("user_club")
        val userPassword=intent.getStringExtra("user_password")

        // 初始化控件
        editUserName = findViewById(R.id.editUserName)
        editUserAcademy = findViewById(R.id.editUserAcademy)
        editUserClub = findViewById(R.id.editUserClub)
        editUserPassword=findViewById(R.id.editUserPassword)
        saveButton = findViewById(R.id.saveButton)

        // 设置初始值
        editUserName.setText(userName)
        editUserAcademy.setText(userAcademy)
        editUserClub.setText(userClub)
        editUserPassword.setText(userPassword)

        // 保存按钮
        saveButton.setOnClickListener {
            // 获取修改后的用户数据
            val updatedName = editUserName.text.toString()
            val updatedAcademy = editUserAcademy.text.toString()
            val updatedClub = editUserClub.text.toString()
            val updatePassword=editUserPassword.text.toString()
            // 返回修改后的数据
            val resultIntent = Intent()
            resultIntent.putExtra("updated_name", updatedName)
            resultIntent.putExtra("updated_academy", updatedAcademy)
            resultIntent.putExtra("updated_club", updatedClub)
            resultIntent.putExtra("updated_password",updatePassword)
            setResult(Activity.RESULT_OK, resultIntent)
            finish() // 返回
        }
    }
}


